﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace HUGATE.Item
{
    public partial class Login : System.Web.UI.UserControl
    {

        #region Event Functions

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            Session["user"] = null;
            Session["UserCoreLibs"] = null;

            WebLibs.User objUser1 = new WebLibs.User(txtLogIn.Text, txtPass.Text.Trim() == "" ? "123456" : txtPass.Text);
            objUser1.strStoreName = "System_User_Login";
            objUser1.strFieldNameFunction = "FunctionID";
            objUser1.strListFieldName = "FunctionID";

            objUser1.Login();

            if (objUser1.bolIsLogin)
                Session["user"] = objUser1;
            else
            {
                objUser1 = new WebLibs.User(txtLogIn.Text, CoreLibs.Cryptography.HashingMD5(txtPass.Text.Trim() == "" ? "123456" : txtPass.Text));
                objUser1.strStoreName = "System_User_Login";
                objUser1.strFieldNameFunction = "FunctionID";
                objUser1.strListFieldName = "FunctionID";

                objUser1.Login();

                if (objUser1.bolIsLogin)
                    Session["user"] = objUser1;
            }

            RaisePostBackEvent(null);
            Response.Redirect("Default.aspx");
        }

        #endregion

        #region Event Handler

        public delegate void LogInDelegate(object sender, EventArgs e);
        public event LogInDelegate LogInEvent = null;

        protected void RaisePostBackEvent(EventArgs e)
        {
            if (LogInEvent != null)
                LogInEvent(this, e);
        }

        #endregion

    }
}